package com.travel.mapper.admin;

import com.travel.model.entity.auth.Admin;
import org.apache.ibatis.annotations.*;
//管理员mapper 查询管理员信息 插入管理员信息 更新管理员信息 
@Mapper
public interface AdminMapper {
    
    @Select("SELECT * FROM admin WHERE username = #{username}")
    Admin findByUsername(@Param("username") String username);
    
    @Select("SELECT * FROM admin WHERE id = #{id}")
    Admin findById(@Param("id") Long id);
    
    @Select("SELECT COUNT(*) FROM admin WHERE username = #{username}")
    int existsByUsername(@Param("username") String username);
    
    @Select("SELECT COUNT(*) FROM admin WHERE email = #{email}")
    int existsByEmail(@Param("email") String email);
    
    @Insert("INSERT INTO admin(username, password, email, nickname, status, created_time, updated_time) " +
            "VALUES(#{username}, #{password}, #{email}, #{nickname}, #{status}, #{createdTime}, #{updatedTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(Admin admin);
    
    @Update("UPDATE admin SET password = #{password}, email = #{email}, nickname = #{nickname}, " +
            "status = #{status}, updated_time = #{updatedTime} WHERE id = #{id}")
    int update(Admin admin);
} 